# coding=utf-8
from tvtk.api import tvtk
from mytvtk.util.scene import event_loop, ivtk_scene

# 构建ImageData数据集
img = tvtk.ImageData(spacing=(1, 1, 1), origin=(1, 2, 3), dimensions=(3, 4, 5))
# img.get_point(0)获得网格中第一个点的坐标值
print("ImageData数据集:")
for n in range(6):  # 输出image对象的所有点
    print("%.1f,%.1f,%.1f" % img.get_point(n))

# RectilinearGrid使用
# （因为不均匀，所以网格对象上的所有点表示对象交点）
import numpy as np

x = np.array([0, 3, 9, 15])  # 实现网格的构建
y = np.array([0, 1, 5])
z = np.array([0, 2, 3])
r = tvtk.RectilinearGrid()  # 因为不会根据属性调整数组长度，所以需要设置
r.x_coordinates = x
r.y_coordinates = y
r.z_coordinates = z
r.dimensions = len(x), len(y), len(z)
print("RectilinearGrid数据集:")
for n in range(6):
    print(r.get_point(n))

p0 = [0.0, 0.0, 0.0]
p1 = [0.0, 1.0, 0.0]
p2 = [1.0, 0.0, 0.0]
p3 = [1.0, 1.0, 0.0]


def cone_mapper():
    s = tvtk.ConeSource(height=3.0, radius=1.0, resolution=36)
    m = tvtk.PolyDataMapper()
    m = tvtk.PolyDataMapper(input_connection=s.output_port)
    return m


# 创建数据源
#  创建一个Actor,Action 实体
a = tvtk.Actor(mapper=cone_mapper())
win = ivtk_scene(a)
win.scene.isometric_view()
event_loop()
